package com.etoak.controller;

import com.etoak.common.core.vo.ResultVO;
import com.etoak.entity.Cart;
import com.etoak.service.CartService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cart")
public class CartController {

    @Autowired
    CartService cartService;

    @PostMapping
    public ResultVO<Object> saveOrUpdate(@Valid @RequestBody Cart cart) {
        cartService.saveOrUpdate(cart);
        return ResultVO.success();
    }

    @GetMapping
    public ResultVO<List<Cart>> list(){
        List<Cart> cartList = cartService.getList();
        return ResultVO.success(cartList);
    }

    @DeleteMapping("/{ids}")
    public ResultVO<Object> delete(@PathVariable List<String> ids) {
        cartService.delete(ids);
        return ResultVO.success();
    }
}
